package com.example.black.myapplication.shader;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.SweepGradient;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.example.black.myapplication.R;

/**
 * <pre>
 *     author : 28476
 *     e-mail : hao.wang@1hai.cn
 *     time   : 2019/01/01/17:01
 *     desc   :  环形渲染，梯形渲染
 *     version: 1.0
 * </pre>
 */

public class MyGradientView3 extends View {

    private Bitmap bitmap;
    private BitmapShader shader;
    private Paint paint;
    private int width;
    private int height;
    private float scale;
    private ShapeDrawable shapeDrawable;
    private int[] colors = {Color.RED,Color.GREEN,Color.BLUE,Color.YELLOW};
    private RadialGradient radialGradient;
    private SweepGradient sweepGradient;

    public MyGradientView3(Context context) {
        super(context);
        initConfig();
    }

    public MyGradientView3(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initConfig();
    }

    public MyGradientView3(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initConfig();
    }

    private void initConfig() {

        /*
         * CLAMP 平铺 REPEAT 重复 MIRROR 镜像
         */
        paint = new Paint();
        radialGradient = new RadialGradient(300, 300, 100, colors, null, Shader.TileMode.REPEAT);
        sweepGradient = new SweepGradient(300, 300, colors, null);
        paint.setShader(sweepGradient);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(getResources().getColor(R.color.trans_black));
        canvas.drawRect(0,0,400,400,paint);
    }
}
